import 'package:flutter/material.dart';
import 'package:flutter_bilibili/page/ranking_tab_page.dart';
import 'package:flutter_bilibili/widget/hi_tab.dart';
import 'package:flutter_bilibili/widget/navigation_bar.dart';
import 'package:flutter_bilibili/util/view_util.dart';

class RankingPage extends StatefulWidget {
  @override
  _RankingPageState createState() => _RankingPageState();
}

class _RankingPageState extends State<RankingPage>
    with TickerProviderStateMixin {
  TabController _controller;

  static const TABS = [
    {'key': 'like', 'name': '最热'},
    {'key': 'pubdate', 'name': '最新'},
    {'key': 'favorite', 'name': '收藏'},
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(length: TABS.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: [_buildNavigationBar(), _buildTabView()],
    ));
  }

  _buildNavigationBar() {
    return NavigationBar(
      child: Container(
        margin: EdgeInsets.only(top: 10),
        alignment: Alignment.center,
        child: _tabBar(),
        decoration: bottomBoxShadow(context),
      ),
    );
  }

  _tabBar() {
    return HiTab(
      tabs: TABS.map<Tab>((tab) {
        return Tab(
          text: tab['name'],
        );
      }).toList(),
      fontSize: 16,
      borderWith: 3,
      unselectedlabelColor: Colors.black54,
      controller: _controller,
    );
  }

  _buildTabView() {
    return Flexible(
        child: TabBarView(
            controller: _controller,
            children: TABS.map((tab){
              return RankingTabPage(sort: tab['key']);
            }).toList()));
  }
}
